use std::collections::HashMap;

use gauntlet_common::model::Icons;
use gauntlet_common::model::ImageLike;
use gauntlet_common::model::UiWidgetId;
use iced::widget::Text;
use iced::widget::horizontal_space;
use iced::widget::image;
use iced::widget::svg;

use crate::ui::GauntletComplexTheme;
use crate::ui::theme::Element;
use crate::ui::theme::ThemableWidget;
use crate::ui::theme::text::TextStyle;

pub fn render_image<'a, T: 'a + Clone>(
    data: &HashMap<UiWidgetId, Vec<u8>>,
    widget_id: UiWidgetId,
    image_data: &ImageLike,
    icon_style: Option<TextStyle>,
) -> Element<'a, T> {
    match image_data {
        ImageLike::DataSource(_) => {
            match data.get(&widget_id) {
                Some(bytes) => image(image::Handle::from_bytes(bytes.clone())).into(),
                None => horizontal_space().into(),
            }
        }
        ImageLike::Icons(icon) => {
            match icon_style {
                None => icon_to_bootstrap(icon).into(),
                Some(icon_style) => icon_to_bootstrap(icon).themed(icon_style),
            }
        }
    }
}

pub fn render_svg<'a, T: 'a>(data: &HashMap<UiWidgetId, Vec<u8>>, widget_id: UiWidgetId) -> Element<'a, T> {
    match data.get(&widget_id) {
        Some(bytes) => svg(svg::Handle::from_memory(bytes.clone())).into(),
        None => horizontal_space().into(),
    }
}

pub fn icon_to_bootstrap<'a>(icon: &Icons) -> Text<'a, GauntletComplexTheme> {
    use iced_fonts::bootstrap::*;
    match icon {
        Icons::Airplane => airplane(),
        Icons::Alarm => alarm(),
        Icons::AlignCentre => align_center(),
        Icons::AlignLeft => align_start(),
        Icons::AlignRight => align_end(),
        // Icons::Anchor => ,
        Icons::ArrowClockwise => arrow_clockwise(),
        Icons::ArrowCounterClockwise => arrow_counterclockwise(),
        Icons::ArrowDown => arrow_down(),
        Icons::ArrowLeft => arrow_left(),
        Icons::ArrowRight => arrow_right(),
        Icons::ArrowUp => arrow_up(),
        Icons::ArrowLeftRight => arrow_left_right(),
        Icons::ArrowsContract => arrows_angle_contract(),
        Icons::ArrowsExpand => arrows_angle_expand(),
        Icons::AtSymbol => at(),
        // Icons::BandAid => Bandaid,
        Icons::Cash => cash(),
        // Icons::BarChart => BarChart,
        // Icons::BarCode => ,
        Icons::Battery => battery(),
        Icons::BatteryCharging => battery_charging(),
        // Icons::BatteryDisabled => ,
        Icons::Bell => bell(),
        Icons::BellDisabled => bell_slash(),
        // Icons::Bike => Bicycle,
        // Icons::Binoculars => Binoculars,
        // Icons::Bird => ,
        Icons::Bluetooth => bluetooth(),
        // Icons::Boat => ,
        Icons::Bold => type_bold(),
        // Icons::Bolt => ,
        // Icons::BoltDisabled => ,
        Icons::Book => book(),
        Icons::Bookmark => bookmark(),
        Icons::Box => r#box(),
        // Icons::Brush => Brush,
        Icons::Bug => bug(),
        Icons::Building => building(),
        Icons::BulletPoints => list_ul(),
        Icons::Calculator => calculator(),
        Icons::Calendar => calendar(),
        Icons::Camera => camera(),
        Icons::Car => car_front(),
        Icons::Cart => cart(),
        // Icons::Cd =>
        // Icons::Center =>
        Icons::Checkmark => checktwo(),
        // Icons::ChessPiece =>
        Icons::ChevronDown => chevron_down(),
        Icons::ChevronLeft => chevron_left(),
        Icons::ChevronRight => chevron_right(),
        Icons::ChevronUp => chevron_up(),
        Icons::ChevronExpand => chevron_expand(),
        Icons::Circle => circle(),
        // Icons::CircleProgress100 =>
        // Icons::CircleProgress25 =>
        // Icons::CircleProgress50 =>
        // Icons::CircleProgress75 =>
        // Icons::ClearFormatting =>
        Icons::Clipboard => clipboard(),
        Icons::Clock => clock(),
        Icons::Cloud => cloud(),
        Icons::CloudLightning => cloud_lightning(),
        Icons::CloudRain => cloud_rain(),
        Icons::CloudSnow => cloud_snow(),
        Icons::CloudSun => cloud_sun(),
        Icons::Code => code(),
        Icons::Gear => gear(),
        Icons::Coin => coin(),
        Icons::Command => command(),
        Icons::Compass => compass(),
        // Icons::ComputerChip =>
        // Icons::Contrast =>
        Icons::CreditCard => credit_card(),
        Icons::Crop => crop(),
        // Icons::Crown =>
        Icons::Document => file_earmark(),
        Icons::DocumentAdd => file_earmark_plus(),
        Icons::DocumentDelete => file_earmark_x(),
        Icons::Dot => dot(),
        Icons::Download => download(),
        // Icons::Duplicate => ,
        Icons::Eject => eject(),
        Icons::ThreeDots => three_dots(),
        Icons::Envelope => envelope(),
        Icons::Eraser => eraser(),
        Icons::ExclamationMark => exclamation_lg(),
        Icons::Eye => eye(),
        Icons::EyeDisabled => eye_slash(),
        Icons::EyeDropper => eyedropper(),
        Icons::Female => gender_female(),
        Icons::Film => film(),
        Icons::Filter => filter(),
        Icons::Fingerprint => fingerprint(),
        Icons::Flag => flag(),
        Icons::Folder => folder(),
        Icons::FolderAdd => folder_plus(),
        Icons::FolderDelete => folder_minus(),
        Icons::Forward => forward(),
        Icons::GameController => controller(),
        Icons::Virus => virus(),
        Icons::Gift => gift(),
        Icons::Glasses => eyeglasses(),
        Icons::Globe => globe(),
        Icons::Hammer => hammer(),
        Icons::HardDrive => device_hdd(),
        Icons::Headphones => headphones(),
        Icons::Heart => heart(),
        // Icons::HeartDisabled => ,
        Icons::Heartbeat => activity(),
        Icons::Hourglass => hourglass(),
        Icons::House => house(),
        Icons::Image => image(),
        Icons::Info => info_lg(),
        Icons::Italics => type_italic(),
        Icons::Key => key(),
        Icons::Keyboard => keyboard(),
        Icons::Layers => layers(),
        // Icons::Leaf => ,
        Icons::LightBulb => lightbulb(),
        Icons::LightBulbDisabled => lightbulb_off(),
        Icons::Link => link_fourfivedeg(),
        Icons::List => list(),
        Icons::Lock => lock(),
        // Icons::LockDisabled => ,
        Icons::LockUnlocked => unlock(),
        // Icons::Logout => ,
        // Icons::Lowercase => ,
        // Icons::MagnifyingGlass => ,
        Icons::Male => gender_male(),
        Icons::Map => map(),
        Icons::Maximize => fullscreen(),
        Icons::Megaphone => megaphone(),
        Icons::MemoryModule => memory(),
        Icons::MemoryStick => usb_drive(),
        Icons::Message => chat(),
        Icons::Microphone => mic(),
        Icons::MicrophoneDisabled => mic_mute(),
        Icons::Minimize => fullscreen_exit(),
        Icons::Minus => dash(),
        Icons::Mobile => phone(),
        // Icons::Monitor => ,
        Icons::Moon => moon(),
        // Icons::Mountain => ,
        Icons::Mouse => mouse(),
        Icons::Multiply => x(),
        Icons::Music => music_note_beamed(),
        Icons::Network => broadcast_pin(),
        Icons::Paperclip => paperclip(),
        Icons::Paragraph => text_paragraph(),
        Icons::Pause => pause(),
        Icons::Pencil => pencil(),
        Icons::Person => person(),
        Icons::PersonAdd => person_add(),
        Icons::PersonRemove => person_dash(),
        Icons::Phone => telephone(),
        // Icons::PhoneRinging => ,
        Icons::PieChart => pie_chart(),
        Icons::Capsule => capsule(),
        // Icons::Pin => ,
        // Icons::PinDisabled => ,
        Icons::Play => play(),
        Icons::Plug => plug(),
        Icons::Plus => plus(),
        // Icons::PlusMinusDivideMultiply => ,
        Icons::Power => power(),
        Icons::Printer => printer(),
        Icons::QuestionMark => question_lg(),
        Icons::Quotes => quote(),
        Icons::Receipt => receipt(),
        Icons::Repeat => repeat(),
        Icons::Reply => reply(),
        Icons::Rewind => rewind(),
        Icons::Rocket => rocket(),
        // Icons::Ruler => ,
        Icons::Shield => shield(),
        Icons::Shuffle => shuffle(),
        Icons::Snippets => body_text(),
        Icons::Snowflake => snow(),
        // Icons::VolumeHigh => VolumeUp,
        // Icons::VolumeLow => VolumeDown,
        // Icons::VolumeOff => VolumeOff,
        // Icons::VolumeOn => ,
        Icons::Star => star(),
        // Icons::StarDisabled => ,
        Icons::Stop => stop(),
        Icons::Stopwatch => stopwatch(),
        Icons::StrikeThrough => type_strikethrough(),
        Icons::Sun => sun_fill(), // TODO why Sun isn't in iced_aw?
        Icons::Scissors => scissors(),
        // Icons::Syringe => ,
        Icons::Tag => tag(),
        Icons::Thermometer => thermometer(),
        Icons::Terminal => terminal(),
        Icons::Text => fonts(),
        Icons::TextCursor => cursor_text(),
        // Icons::TextSelection => ,
        // Icons::Torch => ,
        // Icons::Train => ,
        Icons::Trash => trash(),
        Icons::Tree => tree(),
        Icons::Trophy => trophy(),
        Icons::People => people(),
        Icons::Umbrella => umbrella(),
        Icons::Underline => type_underline(),
        Icons::Upload => upload(),
        // Icons::Uppercase => ,
        Icons::Wallet => wallet(),
        Icons::Wand => magic(),
        // Icons::Warning => ,
        // Icons::Weights => ,
        Icons::Wifi => wifi(),
        Icons::WifiDisabled => wifi_off(),
        Icons::Window => window(),
        Icons::Tools => tools(),
        Icons::Watch => watch(),
        Icons::XMark => x_lg(),
        Icons::Indent => indent(),
        Icons::Unindent => unindent(),
    }
}
